package com.cooba.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cooba.R;
import com.cooba.bean.VideoBeans;
import com.lidroid.xutils.BitmapUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/12/30.
 * 视频推荐
 */
public class VideoMyadaptertest extends BaseAdapter {
    private Context context;
    private List<VideoBeans.VideoListEntity> list = new ArrayList<>();

    public List<VideoBeans.VideoListEntity> getList() {
        return list;
    }

    public void setList(List<VideoBeans.VideoListEntity> list) {
        this.list = list;
    }

    public VideoMyadaptertest(Context context, List<VideoBeans.VideoListEntity> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        VideoViewHolder holder = null;
        if (convertView == null) {
            holder = new VideoViewHolder();
            convertView = LayoutInflater.from((context)).inflate(R.layout.video_list_item, parent, false);
            holder.img = (ImageView) convertView.findViewById(R.id.iv_video);
            holder.description = (TextView) convertView.findViewById(R.id.tv_video);
            holder.title = (TextView) convertView.findViewById(R.id.tv_videomsg);
            convertView.setTag(holder);
        } else {
            holder = (VideoViewHolder) convertView.getTag();
        }
        holder.title.setText(list.get(position).getTitle());
        holder.description.setText(list.get(position).getIntro());
        String imgUrl = list.get(position).getImg_url();

        BitmapUtils bitmapUtils = new BitmapUtils(context);
        bitmapUtils.display(holder.img, imgUrl);

        return convertView;
    }

    class VideoViewHolder {
        private ImageView img;
        public TextView title;
        public TextView description;

    }

}
